﻿CREATE TRIGGER [PostPosition_Trg_Update]
ON [acms].[PostPositions]
FOR UPDATE 
AS 
BEGIN
	SET NOCOUNT ON

	Update c
	set [ParentPath] = Replace(c.[ParentPath], b.ParentPath, a.ParentPath)
	FROM Inserted a 
		inner join Deleted b on a.Id = b.Id 
		inner join acms.PostPositions c on isNull(c.PublishDate, '9999/12/31') = isNull(a.PublishDate, '9999/12/31')
	and c.ParentPath like b.ParentPath + '%' and c.PostId <> a.PostId and a.ParentPath <> b.ParentPath
END
;
